package bb.lanxing.lib.devices.ble.ble.base;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import androidx.core.app.NotificationCompat;
import androidx.exifinterface.media.ExifInterface;
//import com.alipay.sdk.packet.d;
import bb.lanxing.lib.base.BaseApplication;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.base.SimpleBluetoothGattCallbackCompat;
import bb.lanxing.lib.devices.core.ble.AbsBleDevice;
//import bb.lanxing.lib.devices.sprint.coroutines.DeviceCoroutinesScopeeKt;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Intrinsics;
import kotlinx.coroutines.BuildersKt;
import kotlinx.coroutines.Dispatchers;
import kotlinx.coroutines.sync.Mutex;
import kotlinx.coroutines.sync.MutexKt;

public abstract class BaseBleSensorDevice extends AbsBleDevice {
    private final BaseApplication context;
    private boolean initializationState;
    private Function0<Unit> initializeCallBack;
    private final Mutex mutex;
    private List<BaseBleService> services;

    public BaseBleSensorDevice(SmartDevice device) {
        super(device);
        Intrinsics.checkNotNullParameter(device, "device");
        BaseApplication baseApplication = BaseApplication.get();
        this.context = baseApplication;
        this.mutex = MutexKt.Mutex(false);
        this.services = new ArrayList();
        init(baseApplication, device.getAddress(), new SensorBluetoothCallback(this, this));
    }

    public final BaseApplication getContext() {
        return this.context;
    }

    public final Mutex getMutex() {
        return this.mutex;
    }

    public final List<BaseBleService> getServices() {
        return this.services;
    }

    public final void setServices(List<BaseBleService> list) {
//        Intrinsics.checkNotNullParameter(list, "<set-?>");
        this.services = list;
    }

    public final boolean getInitializationState() {
        return this.initializationState;
    }

    public final void setInitializationState(boolean z) {
        this.initializationState = z;
    }

    public final Function0<Unit> getInitializeCallBack() {
        return this.initializeCallBack;
    }

    public final void setInitializeCallBack(Function0<Unit> function0) {
        this.initializeCallBack = function0;
    }

    public <T extends BaseBleService> T setUpServices(T service) {
//        Intrinsics.checkNotNullParameter(service, "service");
        this.services.add(service);
        return service;
    }

    @Override
    public void onServicesDiscovered() {
        super.onServicesDiscovered();
//        BuildersKt.launch(DeviceCoroutinesScopeeKt.getDeviceStateScope(this), Dispatchers.getIO(), null, new BaseBleSensorDevice$onServicesDiscovered$1(this, null), 2, null);
    }

    public final void initializeDone() {
        this.initializationState = true;
        Function0<Unit> function0 = this.initializeCallBack;
        if (function0 != null) {
//            function0.mo4664invoke();
        }
    }

    public final class SensorBluetoothCallback<T extends AbsBleDevice> extends SimpleBluetoothGattCallbackCompat<T> {
        final BaseBleSensorDevice this$0;

        public SensorBluetoothCallback(BaseBleSensorDevice baseBleSensorDevice, T client) {
            super(client);
//            Intrinsics.checkNotNullParameter(client, "client");
            this.this$0 = baseBleSensorDevice;
        }

        @Override
        public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int i) {
//            Intrinsics.checkNotNullParameter(gatt, "gatt");
//            Intrinsics.checkNotNullParameter(characteristic, "characteristic");
            super.onCharacteristicRead(gatt, characteristic, i);
//            BuildersKt.launch$default(DeviceCoroutinesScopeeKt.getDeviceStateScope(this.this$0), Dispatchers.getIO(), null, new BaseBleSensorDevice$SensorBluetoothCallback$onCharacteristicRead$1(this.this$0, gatt, characteristic, i, null), 2, null);
        }

        @Override
        public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//            Intrinsics.checkNotNullParameter(gatt, "gatt");
//            Intrinsics.checkNotNullParameter(characteristic, "characteristic");
            super.onCharacteristicChanged(gatt, characteristic);
//            BuildersKt.launch$default(DeviceCoroutinesScopeeKt.getDeviceStateScope(this.this$0), Dispatchers.getIO(), null, new BaseBleSensorDevice$SensorBluetoothCallback$onCharacteristicChanged$1(this.this$0, gatt, characteristic, null), 2, null);
        }
    }

    public final void log(String content) {
//        Intrinsics.checkNotNullParameter(content, "content");
        d(content);
    }
}
